describe("api_accountDetail in SG", function() {

    beforeEach(function() {
        App.initSession();
        App.getSession()._currentTimestamp = new Date();
    });

    describe("_callAccount", function() {

        it("shoule call accountHistory when account is ELNAccount", function() {
            var account = App.ELNAccount.create();
            spyOn(account, 'getProductVO').andReturn({
                productCategory: '',
                accountNumber: '',
                currencyCode: ''
            });
            spyOn(bsoi, 'accountHistory');
            callback = jasmine.createSpy();

            App.api_accountDetail._callAccount({}, account, callback);

            expect(bsoi.accountHistory).toHaveBeenCalled();
        });

        it("shoule call accountHistory when account is UNTAccount", function() {
            var account = App.UNTAccount.create();
            spyOn(account, 'getProductVO').andReturn({
                productCategory: '',
                accountNumber: '',
                currencyCode: ''
            });
            spyOn(bsoi, 'accountHistory');
            callback = jasmine.createSpy();

            App.api_accountDetail._callAccount({}, account, callback);

            expect(bsoi.accountHistory).toHaveBeenCalled();
        });

        it("shoule call accountDetail when account is other account", function() {
            var account = App.BaseAccount.create();
            spyOn(account, 'getProductVO').andReturn({
                productCategory: '',
                accountNumber: '',
                currencyCode: ''
            });
            spyOn(bsoi, 'accountDetail');
            callback = jasmine.createSpy();

            App.api_accountDetail._callAccount({}, account, callback);

            expect(bsoi.accountDetail).toHaveBeenCalled();
        });

    });

    describe("_proAccHistory", function() {

        it("get account success and accountHistoryList is null", function() {
            var response = {
                accountHistoryResponse: {
                    accountHistoryList: [],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T18:58:31.585+0530",
                        nonce: "a08b0eff0b7b34a611b2e529c20a7351"
                    }
                }
            }
            var account = {};
            callback = jasmine.createSpy();
            App.api_accountDetail.callbackAccountDetails = callback;

            App.api_accountDetail._proAccHistory(response, account);

            expect(App.api_accountDetail.callbackAccountDetails).toHaveBeenCalledWith(null);
        });

        it("get account success and accountHistoryList is not null", function() {
            var response = {
                accountHistoryResponse: {
                    accountHistoryList: [{}],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T18:58:31.585+0530",
                        nonce: "a08b0eff0b7b34a611b2e529c20a7351"
                    }
                }
            }
            var account = {};
            callback = jasmine.createSpy();
            App.api_accountDetail.callbackAccountDetails = callback;

            App.api_accountDetail._proAccHistory(response, account);

            expect(App.api_accountDetail.callbackAccountDetails).toHaveBeenCalledWith(account, null);
        });

        it("get account success and accountHistoryList is not null and account is ELNAccount", function() {
            var response = {
                accountHistoryResponse: {
                    accountHistoryList: [{equityAccountDealList:[]}],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T18:58:31.585+0530",
                        nonce: "a08b0eff0b7b34a611b2e529c20a7351"
                    }
                }
            }
            var account = App.ELNAccount.create();
            callback = jasmine.createSpy();
            App.api_accountDetail.callbackAccountDetails = callback;

            App.api_accountDetail._proAccHistory(response, account);

            expect(account.get('equityAccountDealList')).toEqual([]);
            expect(App.api_accountDetail.callbackAccountDetails).toHaveBeenCalledWith(account, null);
        });
        
        it("get account success and accountHistoryList is not null and account is UNTAccount", function() {
            var response = {
                accountHistoryResponse: {
                    accountHistoryList: [{transactionsForUnitTrustList:[]}],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T18:58:31.585+0530",
                        nonce: "a08b0eff0b7b34a611b2e529c20a7351"
                    }
                }
            }
            var account = App.UNTAccount.create();
            callback = jasmine.createSpy();
            App.api_accountDetail.callbackAccountDetails = callback;

            App.api_accountDetail._proAccHistory(response, account);

            expect(account.get('transactionsForUnitTrustList')).toEqual([]);
            expect(App.api_accountDetail.callbackAccountDetails).toHaveBeenCalledWith(account, null);
        });

        it("get account error", function() {
            var response = {
                accountHistoryResponse: {
                    responseHeader: {
                        status: 0,
                        currentTimestamp: "2011-10-01T18:58:31.585+0530",
                        nonce: "a08b0eff0b7b34a611b2e529c20a7351"
                    }
                }
            }
            var account = {};
            callback = jasmine.createSpy();
            App.api_accountDetail.callbackAccountDetails = callback;

            App.api_accountDetail._proAccHistory(response, account);

            expect(App.api_accountDetail.callbackAccountDetails).toHaveBeenCalled();
        });
    });

});